import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:magic_car/UI/Loading.dart';
import 'package:magic_car/common/nodata.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:shared_preferences/shared_preferences.dart';
class DrawrecPage extends StatefulWidget {
  DrawrecPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<DrawrecPage> {
  List formList;
  List rec = new List();
  initState() {
    super.initState();
   
    formList = [
      {
        "title": '客户姓名',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001云A00001云A00',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
    ];
    loaddata();
  }
//加载数据
  loaddata() async {
  //  LoadingPage loadpage = LoadingPage(context);
  //   loadpage.show();
    Map<String, String> map = new Map();
    SharedPreferences pref = await SharedPreferences.getInstance();
    map["id"] = pref.getString('uid');
    String role = pref.getString('role');
    if(role=="0"){
      map["issite"] = "1";
    }else{
      map["ispartner"] = '1';
    }
    print(map);

    HttpHelper.post(HttpHelper.API_GetDraw, (data) async {
      //loadpage.close();
      if (data != null) {
        
        print(data);
        print(data["info"].length.toString());
        if (data["code"].toString() == "1") {
          setState(() {
            rec = data["info"];
            // acountinfo = data["info"];
          });
          

        }
      }
    }, params: map);
  }
  Widget buildcontent() {
    List<Widget> tiles = [];
    Widget content;
    for (var item in rec) {
      tiles.add(Padding(
          padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
          child: Container(
              color: Colors.white,
              child: SizedBox(
                  width: double.infinity,
                  child: new Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      new Padding(
                        padding: new EdgeInsets.fromLTRB(10, 10, 10, 0),
                        child: new Text(
                          '提现金额：'+item['money'],
                          style: TextStyle(
                              fontSize: 14,
                              color: Color.fromRGBO(64, 64, 64, 1)),
                        ),
                      ),
                      new Padding(
                        padding: new EdgeInsets.fromLTRB(10, 10, 10, 0),
                        child: new Text(
                          '提现银行：'+item["bankname"],
                          style: TextStyle(
                              fontSize: 14,
                              color: Color.fromRGBO(64, 64, 64, 1)),
                        ),
                      ),
                      new Padding(
                        padding: new EdgeInsets.fromLTRB(10, 10, 10, 0),
                        child: new Text(
                          '提现账号：'+item["account"],
                          style: TextStyle(
                              fontSize: 14,
                              color: Color.fromRGBO(64, 64, 64, 1)),
                        ),
                      ),
                      new Padding(
                          padding: new EdgeInsets.fromLTRB(10, 10, 10, 0),
                          child: RichText(
                              text: TextSpan(
                                  text: '提现状态：',
                                  style: TextStyle(
                                      fontSize: 14,
                                      color: Color.fromRGBO(64, 64, 64, 1)),
                                  children: <TextSpan>[
                                TextSpan(
                                  text: item['status_str'],
                                  style: TextStyle(
                                      fontSize: 14,
                                      color: Color.fromRGBO(251, 73, 57, 1)),
                                )
                              ]))),
                      new Padding(
                        padding: new EdgeInsets.fromLTRB(10, 10, 10, 10),
                        child: new Text(
                          item['ctime'],
                          style: TextStyle(
                              fontSize: 12,
                              color: Color.fromRGBO(143, 143, 143, 1)),
                        ),
                      ),
                    ],
                  )))));
    }
    content = new Column(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
          title: new Text(
            '提现记录',
            style: TextStyle(color: Colors.black),
          ),
          backgroundColor: Colors.white,
          elevation: 0,
          iconTheme: IconThemeData(
            color: Colors.black, //修改颜色
          ),
        ),
      body: new Center(
        child: Container(
            decoration: new BoxDecoration(
              color: Color.fromRGBO(238, 238, 238, 1),
            ),
            child:
                // new ListView(children: <Widget>[
                Stack(
              children: <Widget>[
                Align(
                  alignment: Alignment.topLeft,
                  child: SizedBox(
                      width: double.infinity,
                      height: 10,
                      child: Padding(
                          padding: new EdgeInsets.fromLTRB(10, 10, 0, 0),
                          // padding: new EdgeInsets.all(10),
                          child:
                              Container(height: 50, child: Text('')))),
                ),
                Align(
                    alignment: Alignment.bottomCenter,
                    child: Padding(
                      padding: new EdgeInsets.fromLTRB(0, 10, 0, 10),
                      child:rec.length>0? new ListView(children: <Widget>[
                        
                        
                        buildcontent()]):Nodata(),
                    )),
              ],
            )
            // buildcontent()
            //]
            ),
      ),
    );
  }
}